package org.ourgrid.broker.business.schedulerdata.executor;

import java.util.ArrayList;
import java.util.List;

import org.ourgrid.broker.business.schedulerdata.SchedulerData;
import org.ourgrid.broker.response.GetFileInfoMessageHandleResponseTO;
import org.ourgrid.common.internal.IResponseTO;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class GetFileInfoExecutor extends AbstractSchedulerDataExecutor {
	
	/**
	 * <GET_FILE_INFO handleId='long' localFileName='String' description='String' 
	 * workerID='String' requestID='long' destinationFileName='String'/> 
	 */
	public List<IResponseTO> execute(SchedulerData command) {
		List<IResponseTO> responses = new ArrayList<IResponseTO>();
		
		Document logDocFile = super.getXMl(command.getXml());
		
		Element element = logDocFile.getDocumentElement();
		
		long handleId = Long.valueOf(element.getAttribute("handleId"));
		String destinationFileName = element.getAttribute("destinationFileName");
		String workerID = element.getAttribute("workerID");
		long requestID = Long.valueOf(element.getAttribute("requestID"));
		
		GetFileInfoMessageHandleResponseTO to = new GetFileInfoMessageHandleResponseTO(handleId, requestID,
				destinationFileName, getAddress(workerID));
		
		responses.add(to);
		
		return responses;
	}
}
